<?php
/*
 * code to process a timesheet periods are updated
 * data is sent from manageperiods.php in a serialised form
*/
// Create connection
include("../inc_files/utils/dbconnection.php");

//get the first form field, the year drop down
$formData = explode('|', $_POST["formdata"], 2);

$stmt = $mysqli->prepare("UPDATE timesheet_periods SET Closed=?,
		SunStatus=?, MonStatus=?, TueStatus=?,
		WedStatus=?, ThurStatus=?, FriStatus=?,
		SatStatus=? WHERE PeriodID = ?");

$stmt->bind_param('iiiiiiiis', $a, $b, $c, $d, $e, $f, $g, $h, $key);
//split each week's data into an array
$rowData= explode("_#", substr($formData[1], 2));

foreach ($rowData as $rowValue){

	//get the ID of the record
	$key = substr($rowValue, 0,7);
	//get the field=value pairs
	$columnData = explode("|",$rowValue);
	$aa = explode("~",$columnData[0]);
	$a = $aa[1];

	$ba = explode("~",$columnData[1]);
	$b = $ba[1];

	$ca = explode("~",$columnData[2]);
	$c = $ca[1];

	$da = explode("~",$columnData[3]);
	$d = $da[1];

	$ea = explode("~",$columnData[4]);
	$e = $ea[1];

	$fa = explode("~",$columnData[5]);
	$f = $fa[1];

	$ga = explode("~",$columnData[6]);
	$g = $ga[1];

	$ha = explode("~",$columnData[7]);
	$h = $ha[1];


	$stmt->execute();

	
}

//tidy up database connection
$stmt->close();
$mysqli->close();


?>